﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using InTheHand.Net.Sockets;
using WinHBM.Core.Bluetooth;

namespace WinHBM.Core.Net.Sockets.Cmd
{
    public class BluetoothDisConnectCmd : SocketCmd
    {
        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(BluetoothDisConnectCmd));
        public override void executeCmd(JObject request, FlashSocketServer socket)
        {

            /*if (BluetoothClientHolder.bluetoothClient == null)
            {
                socket.Send(wrapCmd(CMD_BLUETOOTH_DISCONNECT, "未连接"));
                return;
            }*/

            try
            {
                BluetoothClient client = BluetoothClientHolder.bluetoothClient;
                if (client!= null)
                {
                    client.Close();
                }
                BluetoothClientHolder.bluetoothClient = null;
                BluetoothClientHolder.magicBar = null;
                BluetoothClientHolder.Address = "";
                BluetoothClientHolder.Online = false;

                socket.Send(wrapCmd(CMD_BLUETOOTH_DISCONNECT,"断开成功"));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                socket.Send(wrapCmd(CMD_BLUETOOTH_DISCONNECT, e.Message));
            }
             
        }
    }
}
